package com.suke.controller;

import com.suke.domain.Emp;
import com.suke.domain.Result;
import com.suke.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author java43.熊佳
 * @date 2020/8/20 9:40
 * @Description
 */
@RestController
@RequestMapping("/ec")
public class EmpController {

    @Autowired
    private EmpService empService;

    @RequestMapping(value="emp/{empno}",method= RequestMethod.GET)
    public Result findEmpById(@PathVariable("empno") Integer empno) {
        //return empService.findEmpByEmpno(empno);
        Result res = new Result();
        Emp emp = empService.selectByPrimaryKey(empno.shortValue());
        if(emp==null) {
            res.setMsg("没有查到数据");
            res.setStatus(400);
        }else {
            res.setMsg("一切正常");
            res.setStatus(200);
            res.setObj(emp);
        }

        return res;

    }

    @RequestMapping(value="emp/add",method=RequestMethod.POST)
    public Result addEmp(@RequestBody Emp emp) {
        System.out.println("接收信息："+emp.getEname()+"---"+emp.getJob());
        empService.insert(emp);
        Result res = new Result();
        res.setMsg("添加成功");
        res.setStatus(200);

        return res;
    }
}
